type UserData = {
    name: string;
    age: number;
    email: string;
};

// 将对象所有属性都标记为可选
type PartialUserData = Partial<UserData>;
const partialUser: PartialUserData = {
    name: "John Doe",
    age: 30,
};

// 将所有对象属性都标记为必选
type RequiredUserData = Required<PartialUserData>;
const requiredUserData: RequiredUserData = {
    name: 'John Doe',
    age: 30,
    email: 'john.doe@example.com'
};

// 将所有对象属性都标记为可读
type ReadonlyUserData = Readonly<PartialUserData>;
const readonlyUserData: ReadonlyUserData = {
    name: 'John Doe',
    age: 30,
    email: 'john.doe@example.com'
};

// 标记未声明属性名还未确定的接口类型2
type RecordUserData = Record<string, string>;
const recordUserData: RecordUserData = {
    name: 'John Doe',
    job: 'fe-developer',
    email: 'john.doe@example.com',
    bio: 'Make more interesting things!',
    type: 'vip'
};

// 提取对象类型某些成员
type PickUserData = Pick<UserData, 'name' | 'age'>;
const userPropsData3: PickUserData = {
    name: 'John Doe',
    age: 18,
};

// 移除对象类型某些成员
type OmitUserData = Omit<PickUserData, 'name' | 'age' | 'email'>;
const omitUserData: OmitUserData = {
    phone: '1234567890',
    address: '123 Main St',
    gender: 'male',
    occupation: 'developer',
    education: 'Bachelor',
    hobby: 'reading',
    bio: 'A passionate developer'
};

// 过滤俩个对象类型中不同的成员(差值)
type ExcludeOneData = 'name' | 'age' | 'email' | 'phone' | 'address';
type ExcludeTwoData = 'name' | 'email';
type ExcludeData = Exclude<ExcludeOneData, ExcludeTwoData>;
const excludeData: ExcludeData = 'age'; // 'age' | 'phone' | 'address';

// 过滤俩个对象类型中相同的成员(交集)
type ExtractOneData = 'name' | 'age' | 'email' | 'phone' | 'address';
type ExtractTwoData = 'name' | 'email';
type ExtractData = Extract<ExtractOneData, ExtractTwoData>;
const extractData: ExtractData = 'name'; // 'name' | 'email';

// 提取函数形参类型 [number, number]
type Add = (x: number, y: number) => number;
type AddParams = Parameters<Add>;
const addParams: AddParams = [1, 2];

// 提取函数返回值类型 number
type AddResult = ReturnType<Add>;
const addResult: AddResult = 3;

// 类型查询操作符, 辅助配合使用 ReturnType、AddResult
const addHandler = (x: number, y: number) => x + y;
type AddTwo = typeof addHandler; // (x: number, y: number) => number;
type AddParamsTwo = Parameters<AddTwo>;
type AddResultTwo = ReturnType<AddTwo>;
const addParamsTwo: AddParamsTwo = [1, 2];
const addResultTwo: AddResultTwo = 3;

// 提取异步函数中的形参
async function getPromise() {
    return new Promise<string>((resolve) => {
        setTimeout(() => {
            resolve("Hello, World!");
        }, 1000);
    });
}
type Result = Awaited<ReturnType<typeof getPromise>>; // string 类型






